package com.onlyMe.config.tiles
{
	import com.onlyMe.config.BaseNode;
	import com.onlyMe.config.tiles.tile.TileNode;
	import com.qb9.flashlib.utils.ObjectUtil;

	public final class TilesNode extends BaseNode
	{
		private var _width:Number;
		private var _height:Number;
		private var _angle:int;
		
		private var idMap:Object = {};
		private var typeMap:Object = {};
		
		public function TilesNode()
		{
		}
		
		override protected function extract(node:XML):void
		{
			_width = node.@width;
			_height = node.@height;
			_angle = node.@angle;
		}
		
		override protected function extractChild(node:XML):void
		{
			var tile:TileNode = new TileNode().decode(node);
			idMap[tile.id] = typeMap[tile.type] = tile;
		}
		
		// Attributes

		public function get width():Number
		{
			return _width;
		}

		public function get height():Number
		{
			return _height;
		}

		public function get angle():int
		{
			return _angle;
		}
		
		// Children
		
		public function getByType(type:String):TileNode
		{
			return typeMap[type];
		}
		
		public function getById(id:int):TileNode
		{
			return idMap[id];
		}
		
		public function get tiles():Array
		{
			return ObjectUtil.values(idMap);
		}
	}
}